package
{
	import component.button.InvalidationButton;
	
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.utils.setTimeout;
	
	import obecto.core.FLApplication;
	import obecto.event.FLEvent;

	[SWF(backgroundColor="0xCDCDCD")]
	public class InvalidationSample extends FLApplication
	{
		private var button1 : InvalidationButton;
		private var button2 : InvalidationButton;
		
		public function InvalidationSample()
		{
			super();
			
			stage.frameRate = 35;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			button1 = new InvalidationButton();
			button1.addEventListener(FLEvent.CREATION_COMPLETE, handleButton1CreationComplete);
			
			button2 = new InvalidationButton();
			button2.addEventListener(FLEvent.CREATION_COMPLETE, handleButton2CreationComplete);
			
			setTimeout(testButton1Invalidation, 5000);
			setTimeout(testButton2Invalidation, 10000);
			setTimeout(testButton1Invalidation2, 8000);
		}
		
		private function handleButton1CreationComplete(e : FLEvent) : void 
		{
			button1.x = 100;
			button1.y = 60;
			
			button1.label = "Button One";
			button1.textField.textColor = button1.textColor;
			
			addChild(button1);
		}
		
		private function handleButton2CreationComplete(e : FLEvent) : void 
		{
			button2.x = 350;
			button2.y = 60;
			
			button2.label = "Button Two";
			button2.textField.textColor = button2.textColor;
			
			addChild(button2);
		}
		
		private function testButton1Invalidation() : void 
		{
			for (var i : int = 0; i < 100; i++)
			{
				button1.testNumber = i;
				button1.testString = "Test " + i.toString();
			}
		}
		
		private function testButton1Invalidation2() : void 
		{
			for (var i : int = 0; i < 300; i++)
			{
				button1.testNumber = i;
				button1.testString = "Test " + i.toString();
			}
		}
		
		private function testButton2Invalidation() : void 
		{
			for (var i : int = 100; i < 200; i++)
			{
				button2.testNumber = i;
				button2.testString = "Test " + i.toString();
			}
		}
		
	}
}